package com.hulk.dryad.manage.config.dynamic;

import com.baomidou.dynamic.datasource.processor.DsProcessor;
import com.hulk.dryad.common.constant.CommonConstants;
import com.hulk.dryad.manage.tenant.TenantContextHolder;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @author hulk
 */
public class DsThreadLocalProcessor extends DsProcessor {

    private static final String THREAD_LOCAL_PREFIX = "#"+ CommonConstants.TENANT_ID;

    @Override
    public boolean matches(String key) {
        return key.startsWith(THREAD_LOCAL_PREFIX);
    }

    @Override
    public String doDetermineDatasource(MethodInvocation invocation, String key) {
        return String.valueOf(TenantContextHolder.getTenantId());
    }
}